<div id='login-email' class='weui-cells'>
	<div class='weui-cell bc-input-focus'>
		<div class='weui-cell__hd' style='width:70px;'>邮箱地址</div>
		<div class='weui-cell__bd'><form onsubmit="$('#login-email-send').trigger('click')"><input id="login-email-input" type='email' class='weui-input' name='account' placeholder="输入邮箱地址" /></form></div>
	</div>
	<div class='weui-cell' style="display:none" id="login-email-vcode-cell">
		<div class='weui-cell__hd' style='width:70px;'>图形码</div>
		<div class='weui-cell__bd'><form onsubmit="$('#login-email-send').trigger('click')"><input type='email' id="login-email-vcode" class='login-vcode-input weui-input' name='vcode' placeholder="输入图形码" /></form></div>
		<div class='weui-cell__ft'><img class='vcode'/></div>
	</div>
	<label class="weui-cell weui-check__label login-auto">
		<div class="weui-cell__hd">
			<input checked="checked" id="login-email-auto" type="checkbox" class="weui-check" name="auto">
			<i class="weui-icon weui-icon-checked"></i>
		</div>
		<div class="weui-cell__bd">
			<small>自动登录</small>
		</div>
	</label>
</div>
<div class='errormsg'></div>
<div class='weui-btn-area'>
	<small id="login-email-success" style="display:none;color:maroon;">发送成功，请登录邮箱进行操作</small>
	<button id="login-email-send" class='weui-btn weui-btn_primary'>发送邮箱</button>
</div>
<script>
	login_email = function(){
		var email
		var ee = $("#login-email-input");
		var vv = $("#login-email-vcode");
		var bb = $("#login-email-send");
		var cc = $("#login-email-vcode-cell");
		var ss = $("#login-email-success");
		var email_reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		POST.init("#login-email-send",{
			stop:function(){
				if(bb.hasClass('weui-btn_disabled')) return true;
				ss.hide();
				email = ee.val();
				if(!email_reg.test(email)){
					ee.focus();
					error.top("发送","请输入正确的邮箱");
					return true;
				}
			},
			text:"发送",
			url:"/login/email_send",
			input:function(){
				var vcode = vv.val();
				var auto = $("#login-email-auto").prop("checked")?1:0;
				return {email:email,vcode:vcode,auto:auto}
			},
			success:function(e,res){
				cc.hide();
				ss.fadeIn();
				TIMER.start(bb,10);
				$('#login-email input').val('')
			},
			error:function(e,res){
				switch(res.errormsg){
					case "vcode error":
					cc.show();
					$(".vcode").addClass("active")
					$(".vcode").attr('src','/vcode')
					vv.val('');
					setTimeout(function(){vv.focus()},100);
					break;
					default:
					cc.hide();
				}
			},
			msg:{
				"email exist":"邮箱已被使用",
				"vcode error":"图形码不正确",
				"token cooling":"请稍后再发送",
				"token too much":"尝试太多，请重新发送短信",
			},
		})
	}
	$(function(){
		login_email();
	})
</script>